package com.ruoyi.stock.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.StockTopBoard;
import com.ruoyi.stock.domain.StockZhaBoard;
import com.ruoyi.stock.mapper.StockZhaBoardMapper;
import com.ruoyi.stock.service.IStockZhaBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 涨停炸板个股Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-05
 */
@Service
public class StockZhaBoardServiceImpl implements IStockZhaBoardService {
    @Resource
    private StockZhaBoardMapper stockZhaBoardMapper;

    /**
     * 查询涨停炸板个股
     *
     * @param id 涨停炸板个股主键
     * @return 涨停炸板个股
     */
    @Override
    public StockZhaBoard selectStockZhaBoardById(Long id) {
        return stockZhaBoardMapper.selectStockZhaBoardById(id);
    }

    /**
     * 查询涨停炸板个股列表
     *
     * @param stockZhaBoard 涨停炸板个股
     * @return 涨停炸板个股
     */
    @Override
    public List<StockZhaBoard> selectStockZhaBoardList(StockZhaBoard stockZhaBoard) {
        return stockZhaBoardMapper.selectStockZhaBoardList(stockZhaBoard);
    }

    /**
     * 新增涨停炸板个股
     *
     * @param stockZhaBoard 涨停炸板个股
     * @return 结果
     */
    @Override
    public int insertStockZhaBoard(StockZhaBoard stockZhaBoard) {
        stockZhaBoard.setCreateTime(DateUtils.getNowDate());
        return stockZhaBoardMapper.insertStockZhaBoard(stockZhaBoard);
    }

    @Override
    public AjaxResult importData(List<StockZhaBoard> list, boolean updateSupport) {
        if (list != null && list.size() > 0) {
            Date stDate = list.get(0).getStDate();
            stockZhaBoardMapper.deleteStockZhaBoardByDate(stDate);
            Date nowDate = DateUtils.getNowDate();
            for (StockZhaBoard data : list) {
                data.setCreateTime(nowDate);
                stockZhaBoardMapper.insertStockZhaBoard(data);
            }
            stockZhaBoardMapper.syncMarketDate(stDate);
            return AjaxResult.success("导入成功,导入 "+list.size()+" 条数据 ！ ");

        }
        return AjaxResult.success("表中数据为空");
    }

    /**
     * 修改涨停炸板个股
     *
     * @param stockZhaBoard 涨停炸板个股
     * @return 结果
     */
    @Override
    public int updateStockZhaBoard(StockZhaBoard stockZhaBoard) {
        stockZhaBoard.setUpdateTime(DateUtils.getNowDate());
        return stockZhaBoardMapper.updateStockZhaBoard(stockZhaBoard);
    }

    /**
     * 批量删除涨停炸板个股
     *
     * @param ids 需要删除的涨停炸板个股主键
     * @return 结果
     */
    @Override
    public int deleteStockZhaBoardByIds(Long[] ids) {
        return stockZhaBoardMapper.deleteStockZhaBoardByIds(ids);
    }

    /**
     * 删除涨停炸板个股信息
     *
     * @param id 涨停炸板个股主键
     * @return 结果
     */
    @Override
    public int deleteStockZhaBoardById(Long id) {
        return stockZhaBoardMapper.deleteStockZhaBoardById(id);
    }
}
